<template>
  <div class="login-account">
    <el-form ref="formRef" :model="form" :rules="rules" label-width="60px">
      <el-form-item label="账号" prop="name">
        <el-input v-model="form.name" clearable></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input
          v-model="form.password"
          type="password"
          show-password
          autocomplete="off"
          clearable
        ></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts">
import { ElForm } from 'element-plus'; //为了拿到ELForm类型
import rules from './config/account-config';
export default defineComponent({
  name: 'LoginAccount',
  setup() {
    const formRef = ref<InstanceType<typeof ElForm>>();
    const form = reactive({
      name: '',
      password: ''
    });

    const loginAction = () => {
      formRef.value?.validate((valid) => {
        if (valid) {
          console.log('账号登录');
        } else {
          console.log('error submit');
          return false;
        }
      });
    };

    return {
      formRef,
      form,
      rules,
      loginAction
    };
  }
});
</script>
<style scoped lang="scss"></style>
